home *** CD-ROM | disk | FTP | other *** search
- package com.sun.java.swing;
-
- import java.awt.Color;
- import java.awt.Font;
- import java.awt.FontMetrics;
- import java.awt.Graphics;
- import java.awt.Image;
- import java.awt.Rectangle;
- import java.awt.Shape;
- import java.awt.image.ImageObserver;
- import java.util.Vector;
-
- class SwingGraphics extends Graphics {
- Graphics graphics;
- Rectangle clipRect;
- static final int poolSize = 20;
- private static int needsSetClip = -1;
- private static final Object graphicsPoolKey;
- static Class class$com$sun$java$swing$SwingGraphics;
-
- static {
- Class var10000 = class$com$sun$java$swing$SwingGraphics;
- if (var10000 == null) {
- try {
- var10000 = Class.forName("com.sun.java.swing.SwingGraphics");
- } catch (ClassNotFoundException var0) {
- throw new NoClassDefFoundError(((Throwable)var0).getMessage());
- }
-
- class$com$sun$java$swing$SwingGraphics = var10000;
- }
-
- graphicsPoolKey = var10000;
- }
-
- SwingGraphics(Graphics g) {
- this.init(g);
- }
-
- private void _changeClip(int x, int y, int w, int h, boolean set) {
- if (set) {
- this.clipRect.x = x;
- this.clipRect.y = y;
- this.clipRect.width = w;
- this.clipRect.height = h;
- } else {
- SwingUtilities.computeIntersection(x, y, w, h, this.clipRect);
- }
-
- }
-
- public void clearRect(int x, int y, int width, int height) {
- this.graphics.clearRect(x, y, width, height);
- }
-
- public void clipRect(int x, int y, int width, int height) {
- this.graphics.clipRect(x, y, width, height);
- this._changeClip(x, y, width, height, false);
- }
-
- public void copyArea(int x, int y, int width, int height, int dx, int dy) {
- this.graphics.copyArea(x, y, width, height, dx, dy);
- }
-
- public Graphics create() {
- return createSwingGraphics(this.graphics.create());
- }
-
- public Graphics create(int x, int y, int w, int h) {
- return createSwingGraphics(createGraphics(this.graphics, x, y, w, h));
- }
-
- static Graphics createGraphics(Graphics g, int x, int y, int width, int height) {
- Graphics cg = g.create(x, y, width, height);
- if (needsSetClip != 0) {
- Rectangle r = g.getClipBounds();
- int X = r.x > x ? r.x - x : 0;
- int Y = r.y > y ? r.y - y : 0;
- int W = Math.min(x + width, r.x + r.width) - Math.max(x, r.x);
- int H = Math.min(y + height, r.y + r.height) - Math.max(y, r.y);
- if (needsSetClip == -1 && (x > 0 || y > 0)) {
- Rectangle r2 = cg.getClipBounds();
- if (r2.x == X && r2.y == Y && r2.width == W && r2.height == H) {
- needsSetClip = 0;
- } else {
- needsSetClip = 1;
- }
- }
-
- cg.setClip(X, Y, W, H);
- }
-
- return cg;
- }
-
- public static SwingGraphics createSwingGraphics(Graphics g) {
- if (g == null) {
- return null;
- } else if (g instanceof SwingGraphics) {
- return (SwingGraphics)g;
- } else {
- SwingGraphics sg = getRecycledSwingGraphics();
- if (sg != null) {
- sg.init(g);
- } else {
- sg = new SwingGraphics(g);
- }
-
- return sg;
- }
- }
-
- public void dispose() {
- if (this.graphics != null) {
- this.graphics.dispose();
- this.graphics = null;
- }
-
- this.recycle();
- }
-
- public void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle) {
- this.graphics.drawArc(x, y, width, height, startAngle, arcAngle);
- }
-
- public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgcolor, ImageObserver observer) {
- return this.graphics.drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, bgcolor, observer);
- }
-
- public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer) {
- return this.graphics.drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, observer);
- }
-
- public boolean drawImage(Image img, int x, int y, int width, int height, Color bgcolor, ImageObserver observer) {
- return this.graphics.drawImage(img, x, y, width, height, bgcolor, observer);
- }
-
- public boolean drawImage(Image img, int x, int y, int width, int height, ImageObserver observer) {
- return this.graphics.drawImage(img, x, y, width, height, observer);
- }
-
- public boolean drawImage(Image img, int x, int y, Color bgcolor, ImageObserver observer) {
- return this.graphics.drawImage(img, x, y, bgcolor, observer);
- }
-
- public boolean drawImage(Image img, int x, int y, ImageObserver observer) {
- return this.graphics.drawImage(img, x, y, observer);
- }
-
- public void drawLine(int x1, int y1, int x2, int y2) {
- this.graphics.drawLine(x1, y1, x2, y2);
- }
-
- public void drawOval(int x, int y, int width, int height) {
- this.graphics.drawOval(x, y, width, height);
- }
-
- public void drawPolygon(int[] xPoints, int[] yPoints, int nPoints) {
- this.graphics.drawPolygon(xPoints, yPoints, nPoints);
- }
-
- public void drawPolyline(int[] xPoints, int[] yPoints, int nPoints) {
- this.graphics.drawPolyline(xPoints, yPoints, nPoints);
- }
-
- public void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) {
- this.graphics.drawRoundRect(x, y, width, height, arcWidth, arcHeight);
- }
-
- public void drawString(String str, int x, int y) {
- this.graphics.drawString(str, x, y);
- }
-
- public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle) {
- this.graphics.fillArc(x, y, width, height, startAngle, arcAngle);
- }
-
- public void fillOval(int x, int y, int width, int height) {
- this.graphics.fillOval(x, y, width, height);
- }
-
- public void fillPolygon(int[] xPoints, int[] yPoints, int nPoints) {
- this.graphics.fillPolygon(xPoints, yPoints, nPoints);
- }
-
- public void fillRect(int x, int y, int width, int height) {
- this.graphics.fillRect(x, y, width, height);
- }
-
- public void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) {
- this.graphics.fillRoundRect(x, y, width, height, arcWidth, arcHeight);
- }
-
- public Shape getClip() {
- return this.graphics.getClip();
- }
-
- public Rectangle getClipBounds() {
- return this.graphics.getClipBounds();
- }
-
- public int getClipHeight() {
- return this.clipRect.height;
- }
-
- public int getClipWidth() {
- return this.clipRect.width;
- }
-
- public int getClipX() {
- return this.clipRect.x;
- }
-
- public int getClipY() {
- return this.clipRect.y;
- }
-
- public Color getColor() {
- return this.graphics.getColor();
- }
-
- public Font getFont() {
- return this.graphics.getFont();
- }
-
- public FontMetrics getFontMetrics(Font f) {
- return this.graphics.getFontMetrics(f);
- }
-
- private static synchronized SwingGraphics getRecycledSwingGraphics() {
- SwingGraphics r = null;
- Vector pool = (Vector)SwingUtilities.appContextGet(graphicsPoolKey);
- if (pool == null) {
- return null;
- } else {
- int size;
- if ((size = pool.size()) > 0) {
- r = (SwingGraphics)pool.elementAt(size - 1);
- pool.removeElementAt(size - 1);
- }
-
- return r;
- }
- }
-
- void init(Graphics g) {
- if (g == null) {
- Thread.currentThread();
- Thread.dumpStack();
- }
-
- this.graphics = g;
- this.clipRect = g.getClipBounds();
- if (this.clipRect == null) {
- this.clipRect = new Rectangle(0, 0, Integer.MAX_VALUE, Integer.MAX_VALUE);
- }
-
- }
-
- public boolean isClipIntersecting(Rectangle r) {
- if (this.clipRect.x < r.x + r.width && this.clipRect.x + this.clipRect.width > r.x && this.clipRect.y < r.y + r.height && this.clipRect.y + this.clipRect.height > r.y) {
- return this.clipRect.width != 0 && this.clipRect.height != 0 && r.width != 0 && r.height != 0;
- } else {
- return false;
- }
- }
-
- public void recycle() {
- this.graphics = null;
- recycleSwingGraphics(this);
- }
-
- private static synchronized void recycleSwingGraphics(SwingGraphics g) {
- Vector pool = (Vector)SwingUtilities.appContextGet(graphicsPoolKey);
- if (pool == null) {
- pool = new Vector(20);
- SwingUtilities.appContextPut(graphicsPoolKey, pool);
- }
-
- if (pool.size() < 20) {
- pool.addElement(g);
- }
-
- }
-
- public void setClip(int x, int y, int width, int height) {
- this.graphics.setClip(x, y, width, height);
- this._changeClip(x, y, width, height, true);
- }
-
- public void setClip(Shape clip) {
- this.graphics.setClip(clip);
- if (clip instanceof Rectangle) {
- Rectangle r = (Rectangle)clip;
- this._changeClip(r.x, r.y, r.width, r.height, true);
- }
-
- }
-
- public void setColor(Color c) {
- this.graphics.setColor(c);
- }
-
- public void setFont(Font font) {
- this.graphics.setFont(font);
- }
-
- public void setPaintMode() {
- this.graphics.setPaintMode();
- }
-
- public void setXORMode(Color c1) {
- this.graphics.setXORMode(c1);
- }
-
- public Graphics subGraphics() {
- return this.graphics;
- }
-
- public void translate(int x, int y) {
- this.graphics.translate(x, y);
- }
- }
-